/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufba.lasid.v1.jitclouds.mda.providers;

import br.ufba.lasid.v1.jitclouds.mda.MDA;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.BasicDataCenter;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.IDataCenter;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.ICluster;
import java.util.List;
import java.util.Properties;

/**
 *
 * @author aliriosa
 */
public class DataCenterProvider implements IProvider<IDataCenter> {

    @Override
    public IDataCenter create(Properties options) throws Exception {
                
        BasicDataCenter dc = new BasicDataCenter();
        
        String idDC = MDA.BaseOptions.getProperty(MDA.DCTag);
        String dsDC = MDA.Configuration.getString(idDC + ".description");
        
        dc.setID(idDC);
        dc.setDescription(dsDC);  
                
        List clustersID = MDA.Configuration.getList(idDC + ".cluster.id");
        
        MDA.debug("Loading the Clusters of Data Center " + dc.getID() + "...");
        
        for(Object clusterID : clustersID){
            
            MDA.BaseOptions.setProperty(MDA.ClusterTag, (String)clusterID);
            
            ICluster nc = MDA.createCluster(options);

            dc.addCluster(nc);
            
        }
        
        MDA.debug(dc.size() + " cluster(s) were loaded in " + dc.getID() + "."); 
        MDA.debug("The Data Center " + dc.getID() + "[" + dc.getDescription() + "] has been successfully loaded.");                    
        
        
        return dc;
    }
    
}
